package com.itheima.blockingqueue_2;

import java.util.concurrent.ArrayBlockingQueue;

public class Demo_ArrayBlockingQueue {
    public static void main(String[] args) {
        ArrayBlockingQueue<String> list = new ArrayBlockingQueue<>(1);
        new Thread(() -> {
            int i = 0;
            while (i<10) {
                try {
                    //生产者不停的做
                    list.put("汉堡");
                    i++;
                    System.out.println("生产一个汉堡,桌子上有" + list.size() + "个");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(() -> {
            int i = 0;
            while (i<10) {
                try {
                    //消费者不停的取
                    String s = list.take();
                    i++;
                    System.out.println("吃了一个汉堡,桌子上有" + list.size() + "个");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
